package cn.yunhe.validator;

import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.Date;

public class Order implements Serializable {

    @NotNull
    private Long productId;//产品编号

    @NotNull
    private Long userId;//用户编号

    @Future //只能是将来的日期
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @NotNull
    private Date date; //交易日期

    @NotNull
    @DecimalMin(value = "0.1")  //最小值0.1元
    private Double price;//价格

    @Min(1)     //最小值
    @Max(100)   //最大值
    @NotNull
    private Integer quantity;//数量

    @NotNull
    @DecimalMax("50000.00") //最大交易金额5万
    @DecimalMin("1.00") //最小交易金额1元
    private Double amount;//交易金额

    @Pattern(regexp = "/^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$/", message = "不符合邮件格式")//正则表达式
    private String email;//电子邮箱

    @Size(min = 0, max = 256)  //0到256个字符
    private String note;//备注

    public Order() {
    }

    public Order(Long productId, Long userId, Date date, Double price, Integer quantity, Double amount, String email, String note) {
        this.productId = productId;
        this.userId = userId;
        this.date = date;
        this.price = price;
        this.quantity = quantity;
        this.amount = amount;
        this.email = email;
        this.note = note;
    }

    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }
}
